﻿////////////////////////////////////////////////////////////////////////////////////////////////////
// file:	NADA.cs
//
// summary:	Implements the nada class
////////////////////////////////////////////////////////////////////////////////////////////////////

using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using Dimok.Data.Database;

namespace Dimok.NADA {
	public class Fetch {
		const string PROVIDER_CODE = "N";

		////////////////////////////////////////////////////////////////////////////////////////////////////
		/// <summary>	Gets the connection. </summary>
		///
		/// <value>	The connection. </value>
		////////////////////////////////////////////////////////////////////////////////////////////////////

		static string Connection { get { return ConfigBB.NADA.DBConnection; } }

		////////////////////////////////////////////////////////////////////////////////////////////////////
		/// <summary>	Makes. </summary>
		///
		/// <remarks>	Dimon, 12/21/2010. </remarks>
		///
		/// <param name="Year">	The year. </param>
		///
		/// <returns>	. </returns>
		////////////////////////////////////////////////////////////////////////////////////////////////////

		public static string[] Makes(int Year) {
			return SQLHelperEx.ExecuteScalarArrayEx(Connection, 0, "SELECT Make FROM Makes(@Year) ORDER BY Make", Year);
		}

		////////////////////////////////////////////////////////////////////////////////////////////////////
		/// <summary>	Models. </summary>
		///
		/// <remarks>	Dimon, 12/21/2010. </remarks>
		///
		/// <param name="Year">	The year. </param>
		/// <param name="Make">	The make. </param>
		///
		/// <returns>	. </returns>
		////////////////////////////////////////////////////////////////////////////////////////////////////

		public static string[] Models(int Year, string Make) {
			return SQLHelperEx.ExecuteScalarArrayEx(Connection, 0, "SELECT Model FROM Models(@Year,@Make) ORDER BY Model", Year, Make);
		}

		////////////////////////////////////////////////////////////////////////////////////////////////////
		/// <summary>	Series. </summary>
		///
		/// <remarks>	Dimon, 12/21/2010. </remarks>
		///
		/// <param name="Year">		The year. </param>
		/// <param name="Make">		The make. </param>
		/// <param name="Model">	The model. </param>
		///
		/// <returns>	. </returns>
		////////////////////////////////////////////////////////////////////////////////////////////////////

		public static string[] Series(int Year, string Make, string Model) {
			return SQLHelperEx.ExecuteScalarArrayEx(Connection, 0, "SELECT series FROM Series(@Year,@Make,@Model) ORDER BY Series", Year, Make, Model);
		}

		////////////////////////////////////////////////////////////////////////////////////////////////////
		/// <summary>	Body style. </summary>
		///
		/// <remarks>	Dimon, 12/21/2010. </remarks>
		///
		/// <param name="Year">		The year. </param>
		/// <param name="Make">		The make. </param>
		/// <param name="Model">	The model. </param>
		/// <param name="Series">	The series. </param>
		///
		/// <returns>	. </returns>
		////////////////////////////////////////////////////////////////////////////////////////////////////

		public static string[] BodyStyle(int Year, string Make, string Model, string Series) {
			return SQLHelperEx.ExecuteScalarArrayEx(Connection, 0, "SELECT BodyStyle FROM BodyStyles(@Year,@Make,@Model,@Series) ORDER BY BodyStyle", Year, Make, Model, Series);
		}

		////////////////////////////////////////////////////////////////////////////////////////////////////
		/// <summary>	Book value. </summary>
		///
		/// <remarks>	Dimon, 12/21/2010. </remarks>
		///
		/// <param name="Year">				The year. </param>
		/// <param name="Make">				The make. </param>
		/// <param name="Model">			The model. </param>
		/// <param name="Series">			The series. </param>
		/// <param name="BodyStyle">	The body style. </param>
		/// <param name="Mileage">		The mileage. </param>
		/// <param name="StateCode">	The state code. </param>
		///
		/// <returns>	. </returns>
		////////////////////////////////////////////////////////////////////////////////////////////////////

		public static BlackBook.PriceInfoDS BookValue(int Year, string Make, string Model, string Series, string BodyStyle, int Mileage, string StateCode) {
			BlackBook.PriceInfoDS dsPI = new Dimok.BlackBook.PriceInfoDS();
			DataSet ds = SQLHelperEx.ExecuteDatasetEx(Connection, @"SELECT * FROM ValueByDescription(
				@Period,@Make,@Year,@Model,@Series,@Body,@Mileage,@StateCode,DEFAULT,DEFAULT)",
				DateTime.Today.ToString("yyyyMM"), Make, Year, Model, Series, BodyStyle, Mileage, StateCode);
			if (ds.Tables[0].Rows.Count > 0) {
				DataRow row = ds.Tables[0].Rows[0];
				dsPI.BookValue.AddBookValueRow((int)row["BookValue"], row["ValueDescription"] + "", PROVIDER_CODE,row["Vin_9"] + "", (int)row["MileageAmount"],0);
				dsPI.CarInfo.AddCarInfoRow(row["VIN_9"] + "", row["VIN_9"] + "", Year + "", Make, Model, Series, BodyStyle, Mileage, StateCode, 0, "","",PROVIDER_CODE);
			}
			return dsPI;
		}

		////////////////////////////////////////////////////////////////////////////////////////////////////
		/// <summary>	Book value. </summary>
		///
		/// <remarks>	Dimon, 12/21/2010. </remarks>
		///
		/// <param name="VIN">				The vin. </param>
		/// <param name="Mileage">		The mileage. </param>
		/// <param name="StateCode">	The state code. </param>
		///
		/// <returns>	. </returns>
		////////////////////////////////////////////////////////////////////////////////////////////////////

		public static BlackBook.PriceInfoDS BookValue(string VIN, int Mileage, string StateCode) {
			BlackBook.PriceInfoDS dsPI = new Dimok.BlackBook.PriceInfoDS();
			DataSet ds = SQLHelperEx.ExecuteDatasetEx(Connection,
				"SELECT * FROM ValueByVinPrefix(@VinPrefix,@Mileage,@StateCode,DEFAULT,DEFAULT)",VIN, Mileage, StateCode);
			if (ds.Tables[0].Rows.Count > 0) {
				DataRow row = ds.Tables[0].Rows[0];
				dsPI.BookValue.AddBookValueRow((int)row["BookValue"], row["ValueDescription"] + "",PROVIDER_CODE, VIN, (int)row["MileageAmount"],0);
				dsPI.CarInfo.AddCarInfoRow(VIN, row["VIN_9"] + "", row["Vic_Year"] + "", row["Make"] + "", row["Model"] + "", row["Series"] + "", row["BodyStyle"] + "", Mileage, StateCode, 0, "","",PROVIDER_CODE);
			}
			return dsPI;
		}
	}
}
